<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>

<style>
  .container1 {
    width: 100%;
    height: 100px;
    align-items: center;

    /*元素水平居中*/
    margin-top: 30px;
    margin-bottom: 30px;

  }

  .first {
    display: flex;
    flex-direction: row;
    text-align: left;
  }

  .name1 {
    font-size: 16px;
  }

  .name2 {
    font-size: 16px;
  }

  .name3 {
    font-size: 16px;
  }



  .button1 {
    background-color: rgb(48, 43, 43);
    color: white;
  }

  .button2 {
    background-color: rgb(48, 43, 43);
    color: white;
  }

  .button3 {
    background-color: rgb(48, 43, 43);
    color: white;
  }

  .button4 {
    background-color: rgb(48, 43, 43);
    color: white;
  }

  .container2 {
    width: 100%;
    height: 600px;
    align-items: center;

    /*边框*/
    /*元素水平居中*/
  }

  .demo-ruleForm {
    width: 30%;
  }

  .block {
    text-align: center;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<body>

  <div id="app">

    <div class="container2">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="票据列表" name="first">
          <el-table ref="multipleTable" border :data="billList" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column prop="name" label="用户id" width="120">
              <template slot-scope="scope">
                {{scope.row.userdata.id }}
              </template>
            </el-table-column>
            <el-table-column prop="name" label="用户名称" width="120">
              <template slot-scope="scope">
                {{scope.row.userdata.name }}
              </template>
            </el-table-column>
            <el-table-column prop="name" label="用户地址" width="120">
              <template slot-scope="scope">
                {{scope.row.userdata.address }}
              </template>
            </el-table-column>
            <el-table-column prop="name" label="用户真实姓名" width="120">
              <template slot-scope="scope">
                {{scope.row.userdata.realname }}
              </template>
            </el-table-column>
            <el-table-column prop="phone" label="用户手机号" width="120">
              <template slot-scope="scope">
                {{scope.row.userdata.phone }}
              </template>
            </el-table-column>
            <el-table-column prop="name" label="电影名称" width="120">
              <template slot-scope="scope">
                {{scope.row.moviedata.name }}
              </template>
            </el-table-column>
            <el-table-column prop="info" label="主题id" show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.moviedata.cateid }}
              </template>
            </el-table-column>
            <el-table-column prop="price" label="电影价格" show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.moviedata.price }}
              </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="120">
              <template slot-scope="scope">
                <el-button @click.native.prevent="deleteRow(scope.$index, billList)" type="text" size="small">
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>

</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.bootcss.com/axios/0.19.2/axios.js"></script>

<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
  new Vue({
    el: '#app',
    data: {

      alertUser: false,
      alertForm: {
        id: 2,
        name: '',
        password: '',
        phone: '',
        address: '',
        info: '',
      },
      ruleForm: {
        idsn: '',
        age: '',
        ruleForm: '',
        address: '',
        info: '',
        groupid: "",
      },
      formInline: {
        user: '',
        groupid: ''
      },

      activeName: 'first',
      billList: [],
      multipleSelection: [],
      currentPage3: 5,
      imageUrl: ''
    },
    mounted() {
      this.getBill();
    },
    methods: {
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
      updatemovie() {
        axios.post("/altUser", this.alertForm).then(res => {
          console.log(res.data)
          if (res.data.result == "ok") {
            this.$notify.success({
              title: '成功',
              message: '修改员工信息成功'
            })
            console.log(res.data)
            return;
          }
        })
      },
      createmovie() {
        axios.post("/usermovie/addUsermovie", this.ruleForm).then(res => {
          console.log(res.data)
          if (res.data.result == "ok") {
            this.$notify.success({
              title: '成功',
              message: '添加电影成功'
            })
            console.log(res.data)
            return;
          }
        })
      },

      getBill() {
        this.billList = []
        axios.post("/usermovie/getAllUserMovie", {}).then(res => {
          console.log(res);
          if (res.data.result == "ok") {
            res.data.data.forEach(ele => {
              this.billList.push(ele)
            })
          }
          console.log(this.userList)
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      handleClick(tab, event) {

      },
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleDelete(index, row) {
        console.log(index, row);
      },
      deleteRow(index, rows) {
        axios.post("/usermovie/delUserMovie", { id: rows[index].basedata.id }).then(res => {
          console.log(res);
          if (res.data.result == "ok") {
            this.$notify.success({
              title: '删除成功',
              message: '删除成功！'
            })
            this.getBill();
          }else{
            this.$notify.error({
              title: '删除失败',
              message: '删除失败'
            })
          }
        })
      },
      alertRow(index, row) {
        this.alertUser = true;
        this.alertForm.id = row[index].id;
        this.alertForm.name = row[index].name;
        this.alertForm.phone = row[index].phone;
        this.alertForm.address = row[index].address;
        this.alertForm.info = row[index].info;
        this.alertForm.password = row[index].password;
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      }
    }
  })
</script>

</html>